<?
/**
* Project:     SQL Assembler: the PHP based database query assembler/joiner
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* For questions, help, comments, discussion, etc., please write to the 
* author...
*
* @link http://www.hardwired.hu/
* @link http://sqlassembler.googlecode.com/
* @copyright 2007 Andras Izsof 
* @author Andras Izsof <flatline at hardwired hu>
* @package SQLAssembler
* @version 0.1
*/

/*
TODOGLOBAL:

errorhandling+logging after each function call
*/

//-*-*----------	MYSQL
//-*-*----------	MYSQL
//-*-*----------	MYSQL

class HW_Db_Engine_Mysql extends HW_Db_Engine_Abstract
{
	public function connect($dbconnstring)
	{
		$d = $this->parseConnectionString($dbconnstring);
		
		/*
		If you want to specify a port:
		
		host=http://host.oink.hu:3306/
		or
		host=http://host.oink.hu 
		port=3306
		*/
		
		//$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo");

		$this->dbResourceID = mysql_connect($d['host'] . ($d['port'] ? ':'.$d['port'] : ''), $d['user'], $d['password']);
		
		//Connect to database
		if ($d['dbname'])
			$this->connectDB($d['dbname']);

		return $this->dbResourceID;
	} //function

	public function connectDB($dbname)
	{
		return mysql_select_db($dbname,$this->dbResourceID);
	} //function

	public function disconnect()
	{
		mysql_close($this->dbResourceID);
	} //function

	protected function dbQuery($sql)
	{
		return mysql_query($sql, $this->dbResourceID);
	}

	protected function dbFetchArray()
	{
		return mysql_fetch_array($this->dbResult);
	}

	protected function dbFetchAssoc()
	{
		return mysql_fetch_assoc($this->dbResult);
	}

	protected function dbNumRows()
	{
		return mysql_numrows($this->dbResult);
	}

	protected function dbLastId()
	{
		$sql = "SELECT LAST_INSERT_ID()";
		return $this->qAssoc($sql,0);
	} //function
	
	public function foundRows()
	{
		$sql = "SELECT FOUND_ROWS()";
		return $this->qAssoc($sql,0);
	}
} //class

?>
